package grape.house.service.estatealbum.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import grape.common.service.common.IBaseService;
import grape.common.service.trans.ITransService;
import grape.house.service.estatealbum.po.EstateAlbum;

import java.util.List;

/**
 * <p>
 * 楼盘相册表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2020-09-17
 */
public interface IEstateAlbumService extends IBaseService<EstateAlbum> , ITransService<String,String> {

    public static final String trans_estate_album_name = "trans_estate_album_name";
    public static final String trans_estate_album_code = "trans_estate_album_code";
    public static final String trans_estate_album_image_url = "trans_estate_album_image_url";

    /**
     * 根据编码查询
     * @param code
     * @return
     */
    default EstateAlbum getByCode(String code) {
        assertParamNotEmpty(code,"code 不能为空");
        EstateAlbum estate = new EstateAlbum();
        estate.setCode(code);
        return getOne(estate);
    }
    /**
     * 判断编码是否已存在
     * @param code
     * @return
     */
    default boolean existCode(String code){
        assertParamNotEmpty(code,"code 不能为空");
        EstateAlbum comp = new EstateAlbum();
        comp.setCode(code);
        int r = count(Wrappers.query(comp));
        return r > 0;
    }
    @Override
    default boolean support(String type){
        return isEqualAny(type,trans_estate_album_code, trans_estate_album_name);
    }

    @Override
    default String trans(String type, String key){
        EstateAlbum po = getById(key);
        if (po != null) {
            if (isEqual(type,trans_estate_album_name)) {
                return po.getName();
            }else if (isEqual(type,trans_estate_album_code)) {
                return po.getCode();
            }else if (isEqual(type,trans_estate_album_image_url)) {
                return po.getImageUrl();
            }
        }
        return null;
    }
    /**
     * 根据楼盘id查询
     * @param estateId 楼盘id
     * @return
     */
    default List<EstateAlbum> getByEstateId(String estateId) {
        assertParamNotEmpty(estateId,"estateId不能为空");
        EstateAlbum estateAlbum = new EstateAlbum();
        estateAlbum.setEstateId(estateId);
        return list(estateAlbum);
    }


    /**
     * 根据楼盘id和物业类型id查询
     * @param estateId 楼盘id
     * @param propertyTypeId 物业类型id
     * @return
     */
    default List<EstateAlbum> getByEstateIdAndPropertyTypeId(String estateId,String propertyTypeId) {
        assertParamNotEmpty(estateId,"estateId不能为空");
        assertParamNotEmpty(propertyTypeId,"propertyTypeId不能为空");
        EstateAlbum estateAlbum = new EstateAlbum();
        estateAlbum.setEstateId(estateId);
        estateAlbum.setPropertyTypeId(propertyTypeId);
        return list(estateAlbum);
    }
}
